package com.zw.yzk.kabu.data.repository;

import com.app.common.download.Download;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.Entity;
import com.zw.yzk.kabu.data.network.service.SkinService;
import com.zw.yzk.kabu.data.network.task.SkinDownloadTask;
import com.zw.yzk.kabu.data.network.task.Task;
import rx.Observable;
import rx.functions.Func1;

import javax.inject.Inject;

/**
 * Created by skydar on 2017/4/14.
 */

public class SkinDownloadRepository extends CommonRepository {

    @Inject
    public SkinDownloadRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        SkinService service = ServiceGenerator.createService(SkinService.class);
        final SkinDownloadTask downloadTask = (SkinDownloadTask) addToken(task);

        Download.Builder builder = service.download(downloadTask.url);
        final Download download = builder.tag(downloadTask.url).to(downloadTask.file);
        return Observable.just(download);
    }

    @Override
    protected Func1<? extends Entity, Observable> getServerData() {
        return null;
    }

    protected Observable commonObserve(Task task) {
        return connectServer(addToken(task));
    }
}
